package client.view;

import java.awt.datatransfer.DataFlavor;
import java.util.List;

import core.Card;

/**
 * Encapsulates a card move initiated by a drag & drop action.
 */
public class CardMoveTransferable implements java.awt.datatransfer.Transferable
{
	public CardMoveTransferable(CardMove move) {
		this.move = move;
	}

	public DataFlavor[] getTransferDataFlavors() {
		return FLAVORS;
	}

	public boolean isDataFlavorSupported(DataFlavor flavor) {
		return CARD_MOVE_FLAVOR.equals(flavor);
	}

	public Object getTransferData(DataFlavor flavor) throws java.awt.datatransfer.UnsupportedFlavorException, java.io.IOException {
		return move;
	}

	public static final DataFlavor CARD_MOVE_FLAVOR = new DataFlavor(CardMove.class, "CardMove");
	private static final DataFlavor[] FLAVORS = {CARD_MOVE_FLAVOR};
	private final CardMove move;

	/**
	 * Holds specific information for a <code>CardMoveTransferable</code> about
	 * what card is being moved from where to where. Necessary because
	 * <code>getTransferData</code> can only return a single object.
	 */
	public static class CardMove
	{
		public CardMove(List<Card> cards) {
			this.cards = cards;
		}

		public List<Card> getCards() {
			return cards;
		}

		private final List<Card> cards;
	}
}